package pers.baiban.sqltoword.handler.impl;

import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import pers.baiban.sqltoword.handler.AbstractHeaderProcessor;
import pers.baiban.sqltoword.handler.HeaderProcessor;
import pers.baiban.sqltoword.util.TableUtil;

import java.util.List;

import static pers.baiban.sqltoword.util.TableUtil.Functors.BORDER_BOTTOM;

/**
 * 表头下边框处理器
 *
 * @author 强子初
 * @since 2023/11/29
 */
@Component
@Order(4)
public class HeaderBorderBottomProcessor extends AbstractHeaderProcessor implements HeaderProcessor {

    @Override
    public void doHandler() {
        if (needUpdate(param.getHeaderBorderBottom())) {
            getBottom().forEach(ctBorder -> ctBorder.setVal(param.getHeaderBorderBottom()));
        }

        if (needUpdate(param.getHeaderBorderBottomWidth())) {
            getBottom().forEach(ctBorder -> ctBorder.setSz(param.getHeaderBorderBottomWidth()));
        }
    }

    /**
     * 获取表头下边框
     */
    private List<CTBorder> getBottom() {
        return TableUtil.to(borders, BORDER_BOTTOM);
    }
}